def lazyproperty(func):
    ''' 
    Lazy initialization - Design Pattern
    Implement it by property
    
    Usage - 
        class Foo(object):
            def __init__(self):
                super(Object,self).__init__()
            @lazyproperty
            def sum(self):
                _sum = 0
                for i in range(100):
                    _sum += i
                return _sum
        o = Foo()
        print o.sum
    
    Information -
        the setter raise exception only if the class inhert from object!
    '''
    attr = '_lazy'.join( func.__name__ )
    def get_lazyval(self):
        if not hasattr(self, attr):
            setattr(self, attr, func(self))
        return getattr(self, attr)
    def set_lazyval(self, v):
        raise AttributeError('The lazy property is read-only')
    return property(get_lazyval, set_lazyval)
    
class A(object):
    def __init__(self):
        super(A,self).__init__()
    
    @lazyproperty
    def val(self):
        return 100
    @lazyproperty
    def valLarge(self):
        return 1000

a = A()
print a.val
a.val = 1
print a.val
print a.valLarge

